<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //  * 会定义一个生成器函数
    var inorderTraversal = function* (arr) {
      arr = arr.flat(Infinity)
      //  flat() 按照一个可指定的深度递归遍历数组
      for (let num of arr) {
        yield num
        // yield 关键字 使生成器函数执行暂停
      }
    };

    const gen = inorderTraversal([1, [2, 3]]);
    gen.next().value; // 1
    gen.next().value; // 2
    gen.next().value; // 3
    console.log(gen)

  </script>
</body>

</html>